package com.per.mybootall.aop.example2;

import com.per.mybootall.pojo.UserPo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 第一个切面
 * */
@Aspect
@Component
@Order(0)
public class PermissionSecondAdvice {
    // 定义一个切面，括号内写入第1步中自定义注解的路径
    @Pointcut("@annotation(com.per.mybootall.aop.example2.PermissionAnnotation)")
    private void permissionCheck() {
    }

    @Around("permissionCheck()")
    public Object permissionCheckFirst(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("===================第一个切面===================：" + System.currentTimeMillis());
        Object[] obj= joinPoint.getArgs();
        System.out.println("------>>>>>>>>>"+joinPoint.getTarget().getClass().getName());
        for(Object ob:obj){
            UserPo userPo=(UserPo)ob;
            System.out.println(userPo.getUsername());
        }
        return joinPoint.proceed();
    }

    @Before("permissionCheck()")
    public void theBefore(){
        System.out.println("进入切面之前的处理==》》");
    }
    @After("permissionCheck()")
    public void theafter(){
        System.out.println("进入切面之后的处理==>>");
    }
}
